import {
  pickedVertexData,
  pickedFaceData,
  pickedLineData,
  pickedModelData,
  EventsRes,
  IdObj,
  MouseInfo,
  IAssemblyDocTreeNode,
} from '@amcax/base';
import { MouseActionInputProps } from '@app-cad/common/components/pick-input/mouse-action-input';
import { PickedProduct } from './pick-product';

export const PickInputEvents = {
  Input3dFocused: 'input3dFocused',
  Input2dFocused: 'input2dFocused',
  TargetPicked: 'targetPicked',
} as const;

export type pickedLawCurveData = {
  title: string;
  dxid: string;
};

export enum PickInputValueType {
  Vertex,
  Surface,
  Plane,
  Line,
  Curve,
  Model,
  Sketch,
  Frame,
  // 零件和装配
  Product,
  // 总装配
  FullProduct,
  ALL,
  LawCurve,
  // 临时面
  TempFace,
  // 零件陈列
  PartArray,
}

export type pickedProductData = {
  assisObj: PickedProduct;
  assemblyInfo: IAssemblyDocTreeNode;
  idInfo: IdObj;
  productId: string;
  mouse: MouseInfo;
};

export type MultiPickResult =
  | pickedVertexData
  | pickedFaceData
  | pickedLineData
  | pickedModelData
  | pickedProductData;

export type BasePickInputProps<T = MultiPickResult[]> = Omit<
  MouseActionInputProps,
  'onRegister' | 'onUnregister' | 'onFocus' | 'onBlur'
> & {
  value?: T;
  onPick?: (
    picked?: T,
    ev?: EventsRes<PointerEvent>,
    needFocusNext?: boolean,
  ) => void;
  nameRenderer?: (
    v:
      | pickedFaceData
      | pickedLineData
      | pickedVertexData
      | pickedModelData
      | pickedProductData,
  ) => string;
  onCurvedLawPick?: (
    picked?: pickedLawCurveData,
    ev?: EventsRes<PointerEvent>,
    needFocusNext?: boolean,
  ) => void;
  // 完全受控，value为null时视为置空，仅在外部value改变时试图绘制preview
  controlled?: boolean;
  allowPickType?: PickInputValueType[];
  disallowedPickType?: PickInputValueType[];
  isMulti?: boolean;
  // 拾取曲线时是否显示方向
  showArrow?: boolean;
  // 拾取曲线若显示方向，是否允许反转方向
  curveReversable?: boolean;
  allowInfiniteLine?: boolean;
  allowInfinitePlane?: boolean;

  allowDuplicate?: boolean;

  // 若当前正在编辑某元素，则默认禁止选择该元素和依赖该元素的其他元素
  // 设为true来禁用该行为
  ignoreGlobalPickFilter?: boolean;

  // 若不为空，则经函数检验为true的元素才能被实际拾取到（不影响鼠标hover）
  pickFilter?: (target: any) => boolean;

  onFocus?: VoidFunction;
  onBlur?: VoidFunction;

  allowMarqueeSelect?: boolean;
  alwaysPreserverSuffix?: boolean;
  highlightSelection?: boolean;
  allowPickInvisibleAssembleFromLeftPanel?: boolean;
  noDuplicateProduct?: boolean;
};
